import { _decorator, Component, EventTouch, Input, input,  Collider, ITriggerEvent} from 'cc';
import { Contant } from '../framework/Contant';
const { ccclass, property } = _decorator;

@ccclass('airOpera')
export class airOpera extends Component {

    @property
    public speed =1

    @property
    public speedZ =0.1

    start() {
        input.on(Input.EventType.TOUCH_MOVE, this._onTouchMove, this)
    }

    onEnable() {
        const collider = this.getComponent(Collider)
        collider.on('onTriggerEnter',this._onTriggerEnter, this);
    }

    onDisable() {
        const collider = this.getComponent(Collider)
        collider.off('onTriggerEnter',this._onTriggerEnter, this);
    }

    // update(deltaTime: number) {
        
    // }

    _onTouchMove(event: EventTouch) {
        const delta = event.getDelta()
        let pos = this.node.position
        this.node.setPosition(pos.x + 0.01 * this.speed * delta.x, 0, pos.z - this.speedZ * delta.y)
    }

    _onTriggerEnter(event: ITriggerEvent){
        console.log("监听：",this.node)
        const otherGroup = event.otherCollider.getGroup()
        if(otherGroup === Contant.CollisionType.ENEMY_PLANE || otherGroup === Contant.CollisionType.ENEMY_BULLET){
            console.log("被击中飞机")
        }
    }
    
}


